<?php
require_once("Elements.php");

class CreateOrEditInvitation extends Zend_Form {

	private $invitation;
	private $user;
	
	/**
	 * 
	 * @param $invitation invitation
	 * @param $user user
	 */
	public function CreateOrEditInvitation($invitation, $user) {
		$this->invitation = $invitation;
		$this->user = $user;
		$this->__construct();
	}
	
	public function init() {		
		$categories = Category::findAllAvailableCategory();
		$themes = Theme::findAllAvaiableThemes();
		
		$this->setMethod('post');
		$this->setAttrib('id', 'createInvitation');
		
		$selectedCategory = null;
		$selectedTheme = null;
		
		$elements = new Elements();
		
		if (isset($this->invitation)) {
			$element = new Zend_Form_Element_Hidden("iid");
			$element->setValue($this->invitation->id);
			$this->addElement($element);
			
			$selectedCategory = Invitation::getCategory($this->invitation);
			$selectedTheme = Invitation::getTheme($this->invitation);
		}
		if (isset($this->user)) {
			$element = new Zend_Form_Element_Hidden("user_id");
			$element->setValue($this->user->id);
			$this->addElement($element);
		}
		
		$element = $elements->getInvitationCategorySelect($categories, $selectedCategory);
		$this->addElement($element);
		
		$element = $elements->getInvitationThemeSelect($themes, $selectedTheme);	
		$this->addElement($element);

		
        $this->addDisplayGroup(array('category', 'theme'),'step1');
		$this->getDisplayGroup('step1')->removeDecorator('DtDdWrapper');
		
		$element = $elements->getInvitationTitleTextField($this->invitation);
		$this->addElement($element);
				
		$element = $elements->getInvitationDateTextField($this->invitation);
		$this->addElement($element);
				
		$element = $elements->getInvitationDescriptionTextareaField($this->invitation);
		$this->addElement($element);
		
		$element = $elements->getInvitationAddressTextareaField($this->invitation);
		$this->addElement($element);		
				
		$register = $this->createElement('submit', 'SaveAndAddUser');
		$register->setValue('1');
		$register->setLabel('保存并添加联系人')->removeDecorator('DtDdWrapper');
		$this->addElement($register);
				
		$save = $this->createElement('submit', 'Save');
		$save->setValue('0');
		$save->setLabel('保存')->removeDecorator('DtDdWrapper');
		$this->addElement($save);
		
		
        $this->addDisplayGroup(array('title', 'date','description','address', 'SaveAndAddUser','Save'),'step2');
		$this->getDisplayGroup('step2')->removeDecorator('DtDdWrapper');
				
	}
}
?>